package com.adou.d16.charset;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

public class Test1 {
    public static void main(String[] args) throws UnsupportedEncodingException {
        // 1.编码
        String data = "a我b";
        byte[] bytes = data.getBytes(); // utf-8 5个字节
        System.out.println(Arrays.toString(bytes));

        // 指导编码
        byte[] bytes2 = data.getBytes("gbk"); // utf-8 5个字节
        System.out.println(Arrays.toString(bytes2));

        // 解码
        String s1 = new String(bytes);
        System.out.println(s1);

        String s2 = new String(bytes2);
        System.out.println(s2);

        String s3 = new String(bytes2, "gbk");
        System.out.println(s3);

    }
}
